package es.udc.fbellas.j2ee.tiendaweb.model.administradorfacade.plain;

import javax.sql.DataSource;

import es.udc.fbellas.j2ee.tiendaweb.model.administradorfacade.delegate.AdministradorFacadeDelegate;
import es.udc.fbellas.j2ee.tiendaweb.model.administradorfacade.plain.actions.ServirPedidosAction;
import es.udc.fbellas.j2ee.tiendaweb.model.carrito.Carrito;
import es.udc.fbellas.j2ee.tiendaweb.model.util.GlobalNames;
import es.udc.fbellas.j2ee.util.exceptions.InternalErrorException;
import es.udc.fbellas.j2ee.util.sql.DataSourceLocator;
import es.udc.fbellas.j2ee.util.sql.PlainActionProcessor;

public class PlainAdministradorFacadeDelegate implements AdministradorFacadeDelegate {

	private DataSource dataSource;
    private Carrito carrito;
    
    private DataSource getDataSource() throws InternalErrorException {
        return DataSourceLocator.getDataSource(
            GlobalNames.TIENDAWEB_DATA_SOURCE);
    }

    public PlainAdministradorFacadeDelegate() {
        carrito = new Carrito();
    }
    
	public void ServirPedidos(String login,String enpassword) throws InternalErrorException {
        
        try {
        
        	ServirPedidosAction action = 
                new ServirPedidosAction(login,enpassword);    
        	PlainActionProcessor.process(getDataSource(),action);
            
        } catch (InternalErrorException e) {
            throw e;
        }catch (Exception e) {
            throw new InternalErrorException(e);
        }  
		
	}
    
}
